/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cz.muni.fi.pa165.carpark.TO;

import cz.muni.fi.pa165.carpark.EmployeePosition;
import cz.muni.fi.pa165.carpark.VehicleStatus;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author xmarton1
 */
public class VehicleTO implements Serializable{
    
    private Long id;
    private String stateLicencePlate;
    private String carProducer;
    private String carModel;
    private int yearOfManufacture;
    private String engineType;
    private String vin;
    private int numberOfKms;     
    private EmployeePosition availableForPositions;
    private Set<ServiceCheckTO> controlServiceCheck;
    private VehicleStatus status;
    
    public VehicleTO(){
        this.controlServiceCheck = new HashSet<ServiceCheckTO>();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getStateLicencePlate() {
        return stateLicencePlate;
    }

    public void setStateLicencePlate(String stateLicencePlate) {
        this.stateLicencePlate = stateLicencePlate;
    }

    public String getCarProducer() {
        return carProducer;
    }

    public void setCarProducer(String carProducer) {
        this.carProducer = carProducer;
    }

    public String getCarModel() {
        return carModel;
    }

    public void setCarModel(String carModel) {
        this.carModel = carModel;
    }

    public int getYearOfManufacture() {
        return yearOfManufacture;
    }

    public void setYearOfManufacture(int yearOfManufacture) {
        this.yearOfManufacture = yearOfManufacture;
    }

    public String getEngineType() {
        return engineType;
    }

    public void setEngineType(String engineType) {
        this.engineType = engineType;
    }

    public String getVin() {
        return vin;
    }

    public void setVin(String vin) {
        this.vin = vin;
    }

    public int getNumberOfKms() {
        return numberOfKms;
    }

    public void setNumberOfKms(int numberOfKms) {
        this.numberOfKms = numberOfKms;
    }

    public EmployeePosition getAvailableForPositions() {
        return availableForPositions;
    }

    public void setAvailableForPositions(EmployeePosition availableForPositions) {
        this.availableForPositions = availableForPositions;
    }

    public Set<ServiceCheckTO> getControlServiceCheck() {
        return controlServiceCheck;
    }

    public void setControlServiceCheck(Set<ServiceCheckTO> controlServiceCheck) {
        this.controlServiceCheck = controlServiceCheck;
    }    
    
    public void addControlServiceCheck(ServiceCheckTO checkTO){
        checkTO.setLastCheck(numberOfKms);
        this.controlServiceCheck.add(checkTO);
    }
    
    public void disconnectServiceCheck(ServiceCheckTO serviceCheck){
        if(serviceCheck == null || serviceCheck.getId() == null)
            throw new IllegalArgumentException("ServiceCheck is null or not in database");
        this.controlServiceCheck.remove(serviceCheck);
    }
    
    public Set<ServiceCheckTO> disconnectAllServiceChecks(){
        Set<ServiceCheckTO> result = new HashSet<ServiceCheckTO>(controlServiceCheck);
        this.controlServiceCheck.clear();
        return result;
    }

    public VehicleStatus getStatus() {
        return status;
    }

    public void setStatus(VehicleStatus status) {
        this.status = status;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 41 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final VehicleTO other = (VehicleTO) obj;
         if ((this.id != null && !this.id.equals(other.id)) || (this.id == null && other.id != null)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return this.carProducer + " " + carModel + " " + engineType + " | " + stateLicencePlate;
    }
    
   /* public String getDescription(){
        return this.carProducer + " " + carModel + " " + engineType + " | " + stateLicencePlate;
    }*/
    
    
    
    
    
    
    

}
